import { getHouseResModePage } from '../../api/houseRes'
import config from '../../config/index'
import { RentModel } from '../../enums/model'
Page({
  data: {
    page: 1,
    mode: '',
    config,
    resList: [] as any[]
  },
  async initList() {
    const res = await getHouseResModePage(this.data.page, this.data.mode)
    if (res.statusCode === config.SUCCESS_CODE) {
      this.setData({
        resList: [
          ...this.data.resList,
          ...res.data.data
        ]
      })
    } else {
      wx.showToast({
        title: '获取失败请重试',
        icon: 'none'
      })
    }
  },
  toDetail(e: WechatMiniprogram.TouchEvent) {
    let id = e.currentTarget.dataset.id
    wx.navigateTo({
      url: `/pages/houseDetail/houseDetail?id=${id}`
    })
  },
  onLoad(e: any) {
    let mode = e.mode
    mode === RentModel.FULL ? wx.setNavigationBarTitle({ title: '整租房源' })
      : mode === RentModel.MORE ? wx.setNavigationBarTitle({ title: '合租房源' }) : wx.setNavigationBarTitle({ title: '短租房源' })
    this.setData({
      mode
    })
    this.initList()
  },
  onReachBottom() {
    this.setData({
      page: this.data.page + 1
    })
    this.initList()
  }
})